﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DataAccess.Classes;
using DataAccess;

namespace Webmau.Controls
{
    public partial class BaiVietMoi : System.Web.UI.UserControl
    {
        string idMaBaiViet = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LayDanhSach();
            }
        }

        private void LayDanhSach()
        {
            repBaiMoi.DataSource = BaiViet.BaiMoiViet();
            repBaiMoi.DataBind();

        }
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            repBaiMoi.ItemDataBound += new RepeaterItemEventHandler(repBaiMoi_ItemDataBound);
        }
        void repBaiMoi_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
            {
                BaiViet data = e.Item.DataItem as BaiViet;
                string id = data.MaBaiViet.ToString();

                HyperLink lnkBaiViet = (HyperLink)e.Item.FindControl("lnkBaiViet");
                lnkBaiViet.Text = data.TenBaiViet;
                lnkBaiViet.NavigateUrl = Link.ToBaiViet(id);

                lnkBaiViet.CssClass = id == idMaBaiViet ? "current" : "";
                lnkBaiViet.ToolTip = data.TenBaiViet;
            }
        }
    }
}
